﻿using SaaS.Model.Enums;
using SaaS.Model.Entity.Gateways;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web;
using XCore.Domain.Dto;

namespace SaaS.Model.Dto.Gateways
{
    public class BasicsInput : BasicsSetting, IEntityInput
    {
        public int? Id { get; set; }
        /// <summary>
        /// 标题，防注入
        /// </summary>
        private string _title { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        [Required]
        [StringLength(128, ErrorMessage = "标题不能超过128个字符")]
        public string Title { get { return _title; } set { _title = HttpUtility.HtmlEncode(value); } }
        /// <summary>
        /// 类型
        /// </summary>
        public BasicsType Type { get; set; }
        /// <summary>
        ///  图片，支持多图
        /// </summary>
        [NotMapped]
        public string[] Images { get; set; }
        private string image;
        [Column("Images")]
        public string Image
        {
            get
            {
                if (string.IsNullOrWhiteSpace(image))
                {
                    image = string.Join(",", this.Images);
                }
                return image;
            }
        }
        private string _settingString;
        /// <summary>
        /// 配置信息，不可写
        /// </summary>
        public string SettingString
        {
            get
            {
                if (_settingString == null)
                {
                    _settingString = new BasicsSetting { Url = this.Url, Description = this.Description }.ToString();
                }
                return _settingString;
            }
        }
    }
}
